
<%@ page import="java.util.List" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.Map" %>
<%@ page import="com.alibaba.fastjson.JSONObject" %>

<%@ page import="com.alibaba.fastjson.JSONArray" %>
<%@ page import="com.alibaba.fastjson.JSON" %>

<%@ page import="com.jntoo.db.utils.Convert" %>

<%@ page import="com.gin.util.Request" %>
<%@ page import="com.gin.util.Query" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%@ taglib prefix="ssm" uri="http://ssm" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="css/style.css">
    <script src="js/datepicker/WdatePicker.js"></script>
    <script src="js/jquery.js"></script>

    <script src="js/highcharts/highcharts.js"></script>
    <script src="js/highcharts/modules/exporting.js"></script>
    <script src="js/highcharts/modules/series-label.js"></script>
    <script src="js/highcharts/modules/oldie.js"></script>
</head>
<body style="padding: 30px">


<h3>试卷统计分析</h3>
<div class="pa10 bg-warning">
    <form class="form-inline" id="formSearch" action="?">
        <!-- form 标签开始 -->

        <div class="form-group">
            <i class="glyphicon glyphicon-search"></i>
        </div>

        <div class="form-group">
            试卷
            <select class="form-control class_zuoye4" data-value="${param.shijuan}" id="shijuan" name="shijuan">
                <option value="">请选择</option>

                <%
                    String whe = " 1=1 ";

                    request.setAttribute("whe" , whe);
                %>

                <ssm:sql var="select" type="select"> SELECT * FROM shijuan WHERE ${whe} ORDER BY id desc </ssm:sql>
                <c:forEach items="${select}" var="m"
                ><c:set var="m" value="${m}" scope="request" />
                    <option value="${m.id}">${m.shijuanmingcheng}</option>
                </c:forEach>
            </select>
            <script>
                $(".class_zuoye4").val($(".class_zuoye4").attr("data-value"));
            </script>
            <button type="submit" class="btn btn-default">搜索</button>


        </div>



        <!--form标签结束-->
    </form>
</div>
<%
    if (!Request.get("shijuan").equals("")){
%>
<%
    String where = " 1=1 ";
    if (!Request.get("shijuan").equals("")) {
        where += " AND shijuanid ='" + Request.get("shijuan") + "' ";
    }


    List<HashMap> list = Query.make("shiti").where(where).order("id asc").select();
%>

<table class="table">
    <thead>
    <tr>
        <th style="width: 350px">题目</th>
        <th style="width: 300px">选项</th>
        <th style="width: 200px">正确率</th>
        <th>占比</th>
    </tr>
    </thead>
    <tbody>

    <%
        int i = 0;
        for (HashMap map : list) {
            i++;
            double zhengquerenshuren = 0;
            double errorCount = 0;
    %>
    <tr>
        <td><%=map.get("biaoti")%>
        </td>
        <td>
            <%

                JSONArray rs = JSON.parseArray(String.valueOf(map.get("daan"))); //Info.jsonDecode(map.get("daan"));

                for (Object entry : rs) {
                    //String k = entry.getKey();
                    Map r = (Map) entry; //entry.getValue();

                    long xuanxiang = Query.make("kaoshijieguo")
                            /*.where("timu", Request.get("timu"))*/
                            .where("biaoti", map.get("biaoti"))
                            .where("find_in_set('" + r.get("zimu") + "' , zimu)>0").count();
                    r.put("xuanxiang", xuanxiang);

                    if(Convert.toDouble(r.get("point")) > 0){
                        zhengquerenshuren += xuanxiang;
                    }else{
                        errorCount += xuanxiang;
                    }
            %>

            <p>
                        <span style="float: left; width: 40px">
                            <%=xuanxiang%>人
                        </span>
                <%=r.get("zimu")%>、<%=r.get("title")%>
            </p>
            <%}%>
        </td>
        <td>
            正确人数:<%=zhengquerenshuren%>
            <br>
            错误人数：<%=errorCount%>
            <% if(zhengquerenshuren > 0 || errorCount > 0){ %>
            <br>
            正确率：<%=String.format("%.2f",zhengquerenshuren / (zhengquerenshuren+errorCount) * 100)%>%
            <% } %>
        </td>
        <Td>
            <div id="container<%=i%>" style="max-width:250px;height:250px"></div>
            <script>
                Highcharts.chart('container<%=i%>', {
                    credits: {
                        enabled: false , // 禁用版权信息
                        text: 'HCharts.cn',
                        href: 'http://www.hcharts.cn'
                    },
                    chart: {
                        plotBackgroundColor: null,
                        plotBorderWidth: null,
                        plotShadow: false,
                        type: 'pie'
                    },
                    title: {
                        text: ' '
                    },
                    tooltip: {
                        pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
                    },
                    plotOptions: {
                        pie: {
                            allowPointSelect: true,
                            cursor: 'pointer',
                            dataLabels: {
                                enabled: true,
                                format: '<b>{point.name}</b>: {point.percentage:.1f} %',
                                style: {
                                    color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
                                }
                            }
                        }
                    },
                    series: [{
                        name: 'Brands',
                        colorByPoint: true,
                        data: [
                            <% for (Object entry : rs){
                            Map r = (Map) entry;
                            %>
                            {
                                name: '<%=r.get("zimu")%>',
                                y: <%=r.get("xuanxiang")%>
                            },
                            <% } %>

                        ]
                    }]
                });
            </script>
        </Td>
    </tr>
    <% } %>
    </tbody>

</table>


<br>
<% } %>

</body>
</html>
